﻿using System;
using System.Diagnostics;

namespace Bing
{
    /// <summary>
    /// Contains parameters for a request to the News <see cref="ApiHelper.SourceType"/>.
    /// </summary>
    [DebuggerDisplay("Category:{Category}, SortBy:{SortBy}")]
    public class NewsRequest: IBingRequest
    {
        /// <summary>
        /// Gets or sets a category of news for which to provide results..
        /// </summary>
        /// <value>Specifies a category of news for which to provide results.</value>
        /// <remarks>
        /// Valid values include:
        /// <ul>
        /// <li>rt_Business</li>
        /// <li>rt_Entertainment</li>
        /// <li>rt_Health</li>
        /// <li>rt_Political</li>
        /// <li>rt_Scientific</li>
        /// <li>rt_Sports</li>
        /// <li>rt_US</li>
        /// <li>rt_World</li>
        /// <li>rt_Local</li>
        /// <li>rt_ScienceAndTechnology</li>
        /// </ul>
        /// If no results match the input provided for this parameter, Bing returns the default set of results, which is news belonging to a mix of categories.<br />
        /// Only applicable in en-US market.
        /// </remarks>
        public string Category { get; set; }

        /// <summary>
        /// This property overrides Bing location detection. 
        /// </summary>
        /// <value>This property overrides Bing location detection.</value>
        /// <remarks>
        /// The format for input is US.<i>&lt;state&gt;</i><br />
        /// For example: <b>US.WA</b><br />
        /// This parameter is only applicable in en-US market.<br />
        /// If user provides an invalid string, the location filter is ignored and the default set of results are returned (encompassing all locations).<br />
        /// </remarks>
        public string LocationOverride { get; set; }

        /// <summary>
        /// Gets or sets the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="NewsRequest"/>.
        /// </summary>
        /// <value>Specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="NewsRequest"/>.</value>
        /// <remarks>
        /// The offset specifies the requested position in the result set for the response that is returned for this <see cref="ApiHelper.SourceType"/>. Valid values are between 0 and 1 less than the total number of results.<br />
        /// Note: This property is only applicable when a value is sent for SearchRequest.Query.<br />
        /// </remarks>
        public UInt32? Offset { get; set; }

        /// <summary>
        /// Gets or sets the sort order of results returned from the News <see cref="ApiHelper.SourceType"/>.
        /// </summary>
        /// <value>Specifies the sort order of results returned from the News <see cref="ApiHelper.SourceType"/>.</value>
        public ApiHelper.NewsSortOption? SortBy { get; set; }


        /// <summary>
        /// Creates the query string for the API call.
        /// </summary>
        /// <returns>The query string to append to the call.</returns>
        public string ToQueryString()
        {
            string query = null;
            if (Category != null) query += string.Format("&News.Category={0}", Category);
            if (SortBy != null) query += string.Format("&News.SortBy={0}", SortBy);
            if (LocationOverride != null) query += string.Format("&News.LocationOverride={0}", LocationOverride);
            if (Offset != null) query += string.Format("&News.Offset={0}", Offset);
            return query;
        }
    }
}
